﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Serialization;
using System.Xml;
using CrazyWorship1.ListenerService;

namespace CrazyWorship1
{
    public class ScreenInfo : IXmlSerializable
    {
        public ScreenInfo()
        {
        }
        public ScreenInfo(string clientUrl, DisplayInfo s)
        {
            this._clientUrl = clientUrl;
            this.BitsPerPixel = s.BitsPerPixel;
            this.Bounds = new Rectangle(s.Bounds.Left, s.Bounds.Top, s.Bounds.Width, s.Bounds.Height);
            this.DeviceName = s.DeviceName;
            this.Primary = s.Primary;
            this.WorkingArea = new Rectangle(s.WorkingArea.Left, s.WorkingArea.Top, s.WorkingArea.Width, s.WorkingArea.Height);

        }
        public override bool Equals(object obj)
        {
            if (obj is ScreenInfo)
            {
                ScreenInfo d = (ScreenInfo)obj;
                if (d.ClientUrl == this.ClientUrl)
                    if (d.DeviceName == this.DeviceName)
                        return true;

                return false;
            }
            else
                return base.Equals(obj);
        }
        string _clientUrl;
        public string ClientUrl
        {
            get
            {
                return _clientUrl;
            }
        }
        int _bitsPerPixel;
        public int BitsPerPixel
        {
            get
            {
                return _bitsPerPixel;
            }
            set
            {
                _bitsPerPixel = value;
            }
        }

        public Rectangle Bounds
        {
            get { return _bounds; }
            set { _bounds = value; }
        }
        public string DeviceName
        {
            get { return _deviceName; }
            set { _deviceName = value; }
        }
        public bool Primary
        {
            get { return _primary; }
            set { _primary = value; }
        }
        public Rectangle WorkingArea
        {
            get { return _workingArea; }
            set { _workingArea = value; }
        }
        Rectangle _bounds;
        string _deviceName;
        bool _primary;
        Rectangle _workingArea;


        #region IXmlSerializable Members

        public System.Xml.Schema.XmlSchema GetSchema()
        {
            return null;
        }

        public void ReadXml(XmlReader reader)
        {
            reader.ReadStartElement("ScreenInfo");
            this._deviceName = reader.ReadElementContentAsString("_deviceName", "");
            this._clientUrl = reader.ReadElementContentAsString("_clientUrl", "");
            this._bounds = new Rectangle();//10, 10, 10, 10);
            _bounds.ReadXml(reader);
            this._bitsPerPixel = Convert.ToInt32(reader.ReadElementContentAsString("_bitsPerPixel", ""));
            reader.ReadEndElement();
            reader.MoveToContent();
        }

        public void WriteXml(XmlWriter writer)
        {
            writer.WriteStartElement("ScreenInfo");
            writer.WriteElementString("_deviceName", _deviceName);
            writer.WriteElementString("_clientUrl", _clientUrl);
            _bounds.WriteXml(writer);
            writer.WriteElementString("_bitsPerPixel", _bitsPerPixel.ToString());
            writer.WriteEndElement();

        }

        #endregion
    }
}
